<template>
  <div class="course-exam">
    <!-- 头部信息 -->
    <div class="exam-top">
      <h2 :title="title">{{title}}</h2>
    </div>

    <!-- 选项栏 -->
    <!-- <filter-radio :radios="['全部','完成','未完成']" @cleTabClick="cleItemClick" /> -->

    <!-- 内容栏 -->
    <div class="content">
      <div class="hasList" v-if="examList.length != 0">
        <list-item :dataList="examList" :select="0" :timeShow="true" :types="'exam'" />
      </div>
      <div class="noList" v-else>暂无考试</div>
    </div>
  </div>
</template>

<script>
import ListItem from '@/components/content/List/ListItem';
import FilterRadio from './FilterRadio';

import { tabControlMixin } from '@/common/mixin';

export default {
  name: 'CourseExam',
  components: { FilterRadio, ListItem },
  mixins: [tabControlMixin],
  data() {
    return {
      examList: [] /* 作业数据 */,
    };
  },
  created() {
    this.initItem();
  },
  methods: {
    // 获取不同的信息列表
    initItem() {
      this.iid = this.$store.state.user.id; /* 学号 */
      let data = JSON.parse(sessionStorage.getItem('courseInfo')); /* 课程号 */

      this.$http({
        url: this.$http.adornUrl(`/edu-task/s_selectKcbjTask/${this.iid}/${data.id}`),
        method: 'get',
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        if (data && data.code == 20000) {
          this.title = data.data.kcbjTask[0].name;
          let course = data.data.kcbjTask[0];

          sessionStorage.setItem('topicInfo', JSON.stringify(course)); //Bearer

          if (course.taskList.length != 0) {
            this.examList = [];
            for (let i = 0; i < course.taskList.length; i++) {
              if (course.taskList[i].kind == 1) {
                this.examList.push(course.taskList[i]);
              }
            }
          }

          setTimeout(() => {
            this.initChange();
          }, 0);
        } else {
          this.$message.error('数据获取失败');
        }
      });
    },

    // 判断是否完成
    initChange() {
      const tag = document.querySelectorAll('.tag-icon');
      const status = document.querySelectorAll('.status');

      /* 考试初始化 */
      for (let i = 0; i < this.examList.length; i++) {
        if (status[i].innerHTML == '已完成' && tag[i].classList.contains('exam')) {
          tag[i].classList.add('exam_ok');
        }
      }
    },
  },
};
</script>

<style scoped>
.course-exam {
  padding: 0 30px;
  background-color: #fff;
}
.exam-top {
  padding: 19px 30px;
  border-bottom: 1px solid #f2f2f2;
}
.exam-top h2 {
  height: 22px;
  line-height: 22px;
  font-size: 16px;
  font-weight: 500;
  color: #181e33;
}
.content {
  margin-top: 8px;
}
.noList {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-34%, -50%);
  color: #a8a8b3;
  font-size: 16px;
  font-weight: 400;
  text-align: center;
  line-height: 22px;
}
</style>